<?php

/**
 * Article form.
 *
 * @package    cms
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ArticleForm extends BaseArticleForm
{
  public function configure()
  {
        $this->removeFields();
        $article = new Article();
        //文章状态
        $article_status = $article->getArticleStatus();
        //评论状态
        $article_commend_status = $article->getArticleCommendStatus();
        //分类
        $categorys = Doctrine::getTable('ArticleCategorys')->getTopArticleCategorys(true);
        
        $this->widgetSchema['category'] = new sfWidgetFormChoice(
                    array(
                        'choices'=>$categorys,
                        'expanded'=>false,
                        'multiple'=>false,
                    )
                );

        $this->validatorSchema['category'] = new sfValidatorChoice(
                    array(
                        'choices'=>  array_keys($categorys),
                    )
                );

        $this->widgetSchema['status'] = new sfWidgetFormChoice(
                    array(
                        'choices'=>$article_status,
                        'expanded'=>false,
                        'multiple'=>false,
                    )
                );

        $this->validatorSchema['status'] = new sfValidatorChoice(
                    array(
                        'choices'=>  array_keys($article_status)
                    )
                );

        $this->widgetSchema['comment_status'] = new sfWidgetFormChoice(
                    array(
                        'choices'=>$article_commend_status,
                        'expanded'=>false,
                        'multiple'=>false,
                    )
                );

        $this->validatorSchema['comment_status'] = new sfValidatorChoice(
                    array(
                        'choices'=>array_keys($article_commend_status),
                    )
                );

        $this->validatorSchema['title'] = new sfValidatorRegex(
                    array(
                        'max_length' => 200,
                        'min_length' => 5,
                        'trim' => true,
                        'required' => true,
                        'pattern' => '/^[0-9a-zA-Z\x{4E00}-\x{9FA5}]{2,20}$/u'
                    ),
                    array(
                        'max_length' => '合法长度为5～150个字符',
                        'min_length' => '合法长度为5～150个字符',
                        'required' => '标题必须填写',
                        'invalid' => '标题合法长度为5～150个字符，不能包含特殊字符',

                    )
                );

         $this->validatorSchema['short_title'] = new sfValidatorString(
                    array(
                        'required' => false,
                        'max_length' => 50,
                        'min_length' => 3,
                    ),
                    array(
                        'max_length'=>'简标最大长度不能超过50个字符',
                        'min_length'=>'简标最小长度不能小于3个字符',
                    )
                );

         $this->widgetSchema->setLabels(
                    array(
                        'title'=>'标题',
                        'short_title'=>'简标',
                        'source'=>'来源',
                        'author'=>'作者',
                        'category'=>'分类',
                        'summary'=>'简介',
                        'content'=>'正文',
                        'readers'=>'阅读数',
                        'status'=>'文章状态',
                        'comment_status'=>'评论状态',
                    )
                );

  }

  protected function removeFields()
  {
      unset(
              $this['created_at'],$this['updated_at'],
              $this['recommend_time'],$this['page']
              );
  }

}
